home *** CD-ROM | disk | FTP | other *** search
/ Nebula 1 / Nebula One.iso / Communications / pcomm / Source / data_log.c < prev    next >
Encoding:
C/C++ Source or Header  |  1995-06-12  |  1.7 KB  |  79 lines

  1. /*
  2.  * Open a window to prompt for a path name to be used for the data logging
  3.  * feature.  Also turns on the data logging.  A non-zero return code means
  4.  * we need to restart the input routine.
  5.  */
  6.  
  7. #include <stdio.h>
  8. #include <curses.h>
  9. #include "config.h"
  10. #include "misc.h"
  11. #include "param.h"
  12. #include "status.h"
  13.  
  14. int
  15. data_logging()
  16. {
  17.     extern int fd;
  18.     int ret_code;
  19.     WINDOW *dl_win, *newwin();
  20.     char *ans, *path, *expand(), *get_str(), *strcpy();
  21.     void input_off();
  22.  
  23.     dl_win = newwin(6, 70, 5, 5);
  24.  
  25.     mvwprintw(dl_win, 2, 4, "Default log file: %s", param->logfile);
  26.     mvwaddstr(dl_win, 3, 4, "New log file: ");
  27.     box(dl_win, VERT, HORZ);
  28.  
  29.     mvwattrstr(dl_win, 0, 3, A_BOLD, " Start Data Logging ");
  30.     wmove(dl_win, 3, 18);
  31.     wrefresh(dl_win);
  32.                     /* get the path */
  33.     ret_code = 0;
  34.     while ((ans = get_str(dl_win, PATH, "", " \t\n")) != NULL) {
  35.                     /* give 'em the default */
  36.         if (*ans == '\0')
  37.             path = param->logfile;
  38.         else
  39.             path = expand(ans);
  40.  
  41.                     /* test write permission */
  42.         if (can_write(path)) {
  43.             ret_code++;
  44.             break;
  45.         }
  46.  
  47.         beep();
  48.         mvwattrstr(dl_win, 4, 24, A_BOLD, "No write permission");
  49.         wrefresh(dl_win);
  50.         wait_key(dl_win, 3);
  51.                     /* clean up the mess */
  52.         clear_line(dl_win, 3, 18, TRUE);
  53.         clear_line(dl_win, 4, 24, TRUE);
  54.         wmove(dl_win, 3, 18);
  55.         wrefresh(dl_win);
  56.     }
  57.     if (ret_code) {
  58.         strcpy(status->log_path, path);
  59.         status->log = 1;
  60.         /*
  61.          * Without shared memory, killing and restarting the input
  62.          * routine is the only way to change the name of the file
  63.          * that the input routines uses.
  64.          */
  65. #ifdef SHAREDMEM
  66.         ret_code = 0;
  67. #else /* SHAREDMEM */
  68.         input_off();
  69. #endif /* SHAREDMEM */
  70.     }
  71.     if (fd == -1) {
  72.         werase(dl_win);
  73.         wrefresh(dl_win);
  74.     }
  75.     delwin(dl_win);
  76.  
  77.     return(ret_code);
  78. }
  79.